package stack;

import java.util.Stack;

public class DecodeString {
    public static void main(String[] args){
        String s="3[a2[c]]";
        StringBuilder str= new StringBuilder("");
        StringBuilder str1 = new StringBuilder();
        String str2="";
        int count=0;
        Stack<Character> m = new Stack();
        for(char c:s.toCharArray()){
            str1.setLength(0);
            if (c==']') {
                while (m.peek() != '[')
                    str1.insert(0, m.pop());
                m.pop();
                str2 = str1.toString();
                count=Integer.valueOf(m.pop()+"");
                for (int i = 0; i < count - 1; i++)
                    str1.append(str2);
            }else {
                m.push(c);
            }
            str.append(str1);
        }
        System.out.println(str);

    }
}
